package com.latvia.ui;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.latvia.cookingapp.R;
import com.latvia.managers.AppManager;
import com.latvia.managers.DataManager;
import com.latvia.model.Recipe;

public class CategoryGridViewAdapter extends BaseAdapter {

	 private Context context;
	 private LayoutInflater inflater;
	 private ArrayList<Recipe> recipes;

	    public CategoryGridViewAdapter(Context c) {
	        context = c;
	        int complexity = AppManager.getInstance().getCurrentTab();
	       // recipes = DataManager.getInstance().recipesByComplexity(complexity);
	        recipes = DataManager.getInstance().getRecipes();
	    	this.inflater = (LayoutInflater)context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    }

	    public int getCount() {
	        return recipes.size();
	    }

	    public Object getItem(int position) {
	        return null;
	    }

	    public long getItemId(int position) {
	        return 0;
	    }

	    public View getView(int position, View convertView, ViewGroup parent) {
	    	View recipeItem = convertView;
			if (convertView == null) {
				recipeItem = inflater.inflate(R.layout.category_recipe_item, null);
			} else { 
				recipeItem = (View)convertView;
			}
			Recipe recipe = recipes.get(position);
			
			
			ImageView recipeImage = (ImageView)recipeItem.findViewById(R.id.recipe_item_image);
	        recipeImage.setImageResource(thumbIds[position]);
	        
	        TextView recipeTexView = (TextView)recipeItem.findViewById(R.id.recipe_item_text);
	        recipeTexView.setText(recipe.getName());
	        
	        return recipeItem;
	    }
	    
	    public void setItemList(ArrayList<Recipe> recipes) {
	    	this.recipes = recipes;
	    }

	    // references to our images
	    private Integer[] thumbIds = {
	            R.drawable.sample_0, R.drawable.sample_1,
	            R.drawable.sample_3, R.drawable.sample_2,
	            R.drawable.sample_4, R.drawable.sample_0,
	            R.drawable.sample_0, R.drawable.sample_1,
	            R.drawable.sample_2, R.drawable.sample_3,
	            R.drawable.sample_4, R.drawable.sample_3,
	            R.drawable.sample_1, R.drawable.sample_0,
	            R.drawable.sample_0, R.drawable.sample_1,
	            R.drawable.sample_2, R.drawable.sample_3,
	            R.drawable.sample_4, R.drawable.sample_0,
	            R.drawable.sample_1, R.drawable.sample_3
	    };
	    
	    private Integer[] textIds = {
	    		R.string.recipe_sample_name_1, R.string.recipe_sample_name_2,
	    		R.string.recipe_sample_name_3, R.string.recipe_sample_name_4,
	    		R.string.recipe_sample_name_5, R.string.recipe_sample_name_2,
	    		R.string.recipe_sample_name_1, R.string.recipe_sample_name_6,
	    		R.string.recipe_sample_name_1, R.string.recipe_sample_name_2,
	    		R.string.recipe_sample_name_3, R.string.recipe_sample_name_4,
	    		R.string.recipe_sample_name_5, R.string.recipe_sample_name_6,
	    		R.string.recipe_sample_name_1, R.string.recipe_sample_name_6,
	    		R.string.recipe_sample_name_1, R.string.recipe_sample_name_2,
	    		R.string.recipe_sample_name_3, R.string.recipe_sample_name_4,
	    		R.string.recipe_sample_name_5, R.string.recipe_sample_name_6,
	    };
	    

}
